import router from "@/router";
// import store from "@/store";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import getPageTitle from "@/utils/get-page-title";

NProgress.configure({ showSpinner: false });
router.beforeEach(async (to, from, next) => {
  NProgress.start();
  document.title = getPageTitle(to.meta.title);
  if (localStorage.getItem("token") || to.name === "login") {
    next();
    NProgress.done();
  } else {
    next("/login");
    NProgress.done();
  }
});

router.afterEach(() => {
  NProgress.done();
});
